<template>
  <div>
    <div>给你一个字符串 s ，请你去除字符串中重复的字母，使得每个字母只出现一次。需保证 返回结果的字典序最小（要求不能打乱其他字符的相对位置）</div>
  </div>
</template>

<script lang="ts">
import lodash from 'lodash'
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'arithmetic',
  setup () {
    const s = 'cbacdcbc'
    const arr = new Array(26).fill(0)
    const nums = lodash.countBy(s)
    const res: string[] = []
    for (let i = 0; i < s.length; i++) {
      const ch = s[i]
      if (!arr[ch.charCodeAt(0) - 'a'.charCodeAt(0)]) {
        while (res.length > 0 && res[res.length - 1] > ch) {
          if (nums[res[res.length - 1]] > 0) {
            arr[res[res.length - 1].charCodeAt(0) - 'a'.charCodeAt(0)] = 0
            res.pop()
          } else {
            break
          }
        }
        arr[ch.charCodeAt(0) - 'a'.charCodeAt(0)] = 1
        res.push(ch)
      }
      nums[ch]--
    }
    console.info(res)
    return {}
  }
})
</script>

<style scoped>

</style>
